import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.List;

public class TestDemo {
    public static List<Character> func(String str1,String str2) {
        List<Character> list = new ArrayList<>();
        for(int i = 0;i < str1.length();i++) {
                char ch1 = str1.charAt(i);//获取字符
                if(!str2.contains(ch1 + "")) {//使用查找字符,不存在则添加顺序表中
                    list.add(ch1);
            }
        }
        return list;
    }
    public static void main(String[] args) {
        //ArrayList的缺陷
        //1.能够最快速度找到下标
        //2.删除和插入元素很慢
        //3.增容会对空间造成一定的浪费
    }
    public static void main3(String[] args) {
        List<Character> ret = func("welcome to cvte","come");
        for(char ch:ret) {
            System.out.print(ch);
        }
    }
    public static <listIterator> void main2(String[] args) {
        //arrayList的遍历
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);
        //打印顺序表的多种方法
        //1.直接打印顺序表
        System.out.println(arrayList);
        //2.for循环
        for(int i = 0;i < arrayList.size();i++) {
            System.out.print(arrayList.get(i) + " ");
        }
        System.out.println();
        //3.for->each循环
        for(Integer x:arrayList) {
            System.out.print(x + " ");
        }
        System.out.println();
        //4.迭代器
        Iterator<Integer> it = arrayList.iterator();//每次获得一个值,所以通过循环实现
        while(it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
        //5.
        ListIterator<Integer> it2 = arrayList.listIterator();
        while(it.hasNext()) {
            System.out.print(it2.next() + " ");
        }
        System.out.println();
        //6.从后向前打印
        ListIterator<Integer> it3 = arrayList.listIterator(arrayList.size());
        while(it3.hasPrevious()) {
            System.out.print(it3.previous() + " ");
        }
        System.out.println();
    }
    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(0);
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);

        myArrayList.remove(4);
        myArrayList.display();
    }
}
